<?php

/**
 * @return array
 */
function combineDika() {
    $data = func_get_args();
    $data = current($data);
    $cnt = count($data);
    $result = [];
    $arr1 = array_shift($data);
    foreach($arr1 as $key=>$item)
    {
        $result[] = [$item];
    }

    foreach($data as $key=>$item)
    {
        $result = combineArray($result,$item);
    }
    return $result;
}

/**
 * 两个数组的笛卡尔积
 * @param $arr1
 * @param $arr2
 * @return array
 */
function combineArray($arr1,$arr2) {
    $result = [];
    foreach ($arr1 as $item1)
    {
        foreach ($arr2 as $item2)
        {
            $temp = $item1;
            $temp[] = $item2;
            $result[] = $temp;
        }
    }
    return $result;
}

/**
 * 二维数组排序
 * @param $arr
 * @param $keys
 * @param string $type
 * @param bool $unique
 * @return array
 */
function arraySort($arr, $keys, $type = 'desc', $unique = false){
    $key_value = $new_array = [];
    foreach ($arr as $k => $v) {
        $key_value[$k] = $v[$keys];
    }
    if ($type == 'asc') {
        asort($key_value);
    } else {
        arsort($key_value);
    }
    if ($unique)
        $key_value = array_unique($key_value);
    reset($key_value);
    foreach ($key_value as $k => $v) {
        $new_array[$k] = $arr[$k];
    }
    return $new_array;
}